# MySQL 8.0 配置文件
# 由Ansible自动生成 - {{ ansible_date_time.iso8601 }}

[mysqld]
# 基础配置
port = {{ mysql_port }}
datadir = {{ mysql_datadir }}
socket = /var/lib/mysql/mysql.sock
pid-file = /var/run/mysqld/mysqld.pid

# 字符集配置
character-set-server = {{ mysql_character_set }}
collation-server = {{ mysql_collation }}

# 网络配置
bind-address = {{ mysql_bind_address }}
max_connections = {{ mysql_max_connections }}
max_allowed_packet = {{ mysql_max_allowed_packet }}

# Binlog配置
{% if mysql_binlog_enabled %}
server-id = {{ 100 + (ansible_default_ipv4.address.split('.')[-1] | int) }}
log-bin = mysql-bin
binlog_format = {{ mysql_binlog_format }}
expire_logs_days = {{ mysql_expire_logs_days }}
{% endif %}

# InnoDB配置
innodb_buffer_pool_size = {{ mysql_innodb_buffer_pool_size }}
innodb_log_file_size = {{ mysql_innodb_log_file_size }}
innodb_flush_log_at_trx_commit = {{ mysql_innodb_flush_log_at_trx_commit }}
innodb_flush_method = {{ mysql_innodb_flush_method }}

# 日志配置
log-error = {{ mysql_logdir }}/mysqld.log
slow_query_log = 1
slow_query_log_file = {{ mysql_logdir }}/slow.log
long_query_time = 2

# 安全配置
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

[mysql]
default-character-set = {{ mysql_character_set }}

[client]
default-character-set = {{ mysql_character_set }}
socket = /var/lib/mysql/mysql.sock
